package com.zmn.plat.admin.controller.channel.bail;

import com.zmn.plat.admin.controller.PlatBaseController;
import com.zmn.plat.model.entity.channel.Channel;
import com.zmn.plat.model.entity.channel.bail.ChannelBail;
import com.zmn.plat.model.entity.channel.bail.ChannelBailLog;
import com.zmn.plat.services.interfaces.channel.ChannelService;
import com.zmn.plat.services.interfaces.channel.bail.ChannelBailLogService;
import com.zmn.plat.services.interfaces.channel.bail.ChannelBailService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * 渠道保证金基础查询Controller
 *
 * @author jiafei
 * @since 2021-06-16 09:51:40
 */
@Slf4j
@RestController
@RequestMapping("/channel/bail")
public class ChannelBailListController extends PlatBaseController {

    @Resource
    private ChannelBailService channelBailService;

    @Resource
    private ChannelBailLogService channelBailLogService;

    @Resource
    private ChannelService channelService;

    /**
     * 描述: 查询列表
     *
     * @author jiafei
     * @since 2021-06-16 09:51:40
     */
    @RequestMapping("/list")
    @RequiresPermissions("/channel/bail/list.action")
    public ModelAndView list(@RequestParam(name = "channelId") Integer channelId,
                             @RequestParam(name = "addFlag", required = false) String addFlag) {

        ModelAndView mv = new ModelAndView("channel/bail");
        Channel obj = channelService.findByKey(channelId);
        ChannelBail bail = channelBailService.findById(channelId);

        List<ChannelBailLog> channelBailLogs = channelBailLogService.listByChannelId(channelId);
        Integer mergeSettle = getMergeSettle(channelId);
        obj.setMergeSettle(mergeSettle);
        mv.addObject("obj", obj);
        mv.addObject("bail", bail);
        mv.addObject("bailLogs", channelBailLogs);
        mv.addObject("flag", 18);
        mv.addObject("addFlag", addFlag);

        return mv;
    }

}
